﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Sector7.Restaurant.APs.ForeStation.Controls
{
    /// <summary>
    /// Clock.xaml 的交互逻辑
    /// </summary>
    public partial class Clock : UserControl
    {
        /// <summary>
        /// 是否显示冒号
        /// </summary>
        private bool _isShowColon = false;

        /// <summary>
        /// 是否更新日期
        /// </summary>
        private bool _isUpdateDate = true;

        public Clock()
        {
            InitializeComponent();
        }

        private void uctClock_Loaded(object sender, RoutedEventArgs e)
        {
            UpdateTime();

            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = new TimeSpan(5000000);
            timer.Tick += new EventHandler(timer_Tick);

            timer.Start();
        }

        private void UpdateTime()
        {
            _isShowColon = !_isShowColon;

            DateTime now = DateTime.Now;
            lblHour.Content = string.Format("{0:00}", now.Hour);
            lblColon.Content = _isShowColon ? "." : "";
            lblMinute.Content = string.Format("{0:00}", now.Minute);
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            UpdateTime();
        }
    }
}
